<template>
    <h1>用户理财赎回</h1>

    <table>
        <tr>
            <td>理财名称</td>
            <td>
                {{ Info.F_FName }}
            </td>
        </tr>

        <tr>
            <td>年收益</td>
            <td>
                {{ Info.F_YearMoney }}
            </td>
        </tr>

        <tr>
            <td>最低理财金额</td>
            <td>
                {{ Info.F_MinMoney }}
            </td>
        </tr>

        <tr>
            <td>风险等级</td>
            <td>
                {{ Number(Info.F_FinanLevel) ==0?"低风险": Info.F_FinanLevel?"中风险":"高风险" }}
            </td>
        </tr>

        <tr>
            <td>用户购买金额</td>
            <td>
                {{ Info.UF_Money }}
            </td>
        </tr>

        <tr>
            <td>赎回金额</td>
            <td>
                <input type="text" v-model="Money" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="确认赎回" @click="AddUserFinancingRedeem" >
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';

const route = useRoute();
const router = useRouter();

console.log(route.params.Id);

const Info = ref({
    F_FName:'',
    F_YearMoney:'',
    F_MinMoney:'',
    F_FinanLevel:'',
    UF_Money:'',
    UF_Id:''
})

const Money = ref('');

onMounted(()=>{
    axios({
        method:'get',
        url:'http://localhost:56707/api/Finan/GetUserFinancingInfo',
        params:{
            Id:route.params.Id
        }
    })
    .then(res=>{
        console.log(res.data);
        Info.value = res.data[0];
    })
    .catch(err=>{
        console.log(err);
    })
})

const AddUserFinancingRedeem = ()=>{
    axios({
        method:'post',
        url:'http://localhost:56707/api/Finan/AddUserFinancingRedeem',
        data:{
            UF_Id:route.params.Id,
            UFR_Money:Money.value
        }
    })
    .then(res=>{
        console.log(res.data);
        if(res.data >0){
            alert("用户理财赎回成功");
            router.push("/UserFinanRedeem")
        }else{
            alert("用户理财赎回失败");
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>

